﻿; (function (window, undefined, $) {

    $(document).ready(function () {
        var gridopt = {
            url: options.listUrl,
            colModel: [
                    { display: '编号', name: 'Id', width: "2%", sortable: true, hide: true, align: 'left', iskey: true },
                    { display: '链接类型', name: 'LinkType', width: "4%", sortable: true, align: 'left', process: linktype },
                    { display: '链接名称', name: 'LinkName', width: "5%", sortable: false, align: 'left' },
                    { display: '图片地址', name: 'LinkImg', width: "5%", sortable: false, align: 'left', process: linkImg },
                    { display: '链接地址', name: 'LinkUrl', width: "7%", sortable: false, align: 'left' },
                    { display: '添加时间', name: 'AddTime', width: "5%", sortable: false, align: 'left'},
                    { display: '是否显示', name: 'IsDisplay', width: "3%", sortable: false, align: 'left' },
                    { display: '顺序', name: 'Sequence', width: "2%", sortable: false, align: 'left' },
                    { display: '操作', name: 'Id', width: "10%", sortable: false, align: 'center', process: processOp }
            ],
            sortname: "Id",
            sortorder: "ASC",
            title: false,
            rp: 15,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);

        function linkImg(value, cell) {
            return '<img id="imgShow" style="width: 100px; height: 50px" src="' + value + '" />';
        }
        //这里目前是写死了。
        function linktype(value, cell)
        {
            var ops = [];
            if (value == "1") {
                ops.push("友情链接");
            } else {
                ops.push("合作伙伴");
            }
            return ops.join("");
        }
        function processOp(value, cell) {
            var ops = [];
            ops.push("&nbsp;<a title='编辑' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' ></i>编辑</a>");
            ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            //ops.push("&nbsp;<a title='添加黑名单' href='javascript:;'  onclick=\"util.AddBlack('", value, "')\"><i class='fa fa-edit' ></i>添加黑名单</a>");
            return ops.join("");
        }
        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });
        $("#btnAdd").click(function (e) {
            var url = options.editUrl;
            location.href = url;
        });
        util.Edit = function (id) {
            var url = options.editUrl + "/" + id;
            location.href = url;
        };
        util.Delete = function (id, name) {
            if (!confirm("您确定要执行删除操作吗？")) {
                return false;
            }
            $.post(options.deleteUrl + "/" + id, { id: id },
                  function (res) {
                      if (res.Status > 0) {
                          alert(res.Message);
                          xjgrid.Reload();
                      }
                      else {
                          alert(res.Message);
                      }
                  },
                  "json"
            );
        };
        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });



    });
})(window, undefined, jQuery);